package com.bdqn.util;

import java.util.List;

/**
 * 分页工具类
 * 
 * @author LILIBO
 *
 */
public class Page<T> {

	// 页大小，每页显示多少条数据
	private int pageSize = 5;
	
	// 当前页码，当前所查看的是第几页
	private int currPageNo = 1;
	
	// 总页数
	private int totalPageCount = 0;

	// 数据库表中总数据量
	private int totalCount; // select count(*) from tab

	// 分页的数据
	private List<T> list;

	public int getTotalPageCount() {
		return totalPageCount;
	}

	public void setTotalPageCount(int totalPageCount) {
		this.totalPageCount = totalPageCount;
	}

	public int getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(int totalCount) {
		if (totalCount > 0) {
			this.totalCount = totalCount;
			// 计算总页数
			// 三元表达式：boolean ? 为true时执行 : 为false时执行;
			this.totalPageCount = (totalCount % pageSize == 0) ? (totalCount / pageSize) : (totalCount / pageSize + 1);
		}
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getCurrPageNo() {
		if (totalPageCount == 0) {
			return 0;
		}
		return currPageNo;
	}

	public void setCurrPageNo(int currPageNo) {
		if (currPageNo > 0) {
			// 如果当前页比最大页都大，那么赋值最大页给当前页
			if (totalPageCount != 0 && currPageNo > totalPageCount) {
				currPageNo = totalPageCount;
			}
			this.currPageNo = currPageNo;
		}
		
	}

	public List<T> getList() {
		return list;
	}

	public void setList(List<T> list) {
		this.list = list;
	}

}
